package com.daohang361.ui.interfaces;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import test.ui.TestEIMTree;
import com.csu.client.module.vo.MsgUser;
import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.ServerContex.SessionContex;
import com.daohang361.imqq.ui.BaseFrame;
import com.daohang361.imqq.ui.EIMLoginFrame;
import com.daohang361.imqq.ui.EIMMainFrame;
import com.daohang361.imqq.ui.WaitLoginFrame;

/** 
 * @author naner E-mail:likun3344@163.com
 * @create time：2011-4-10 下午08:55:13 
 * IMQQ登陆程序
 */
public class IMQQLogin implements Login {
private static int qqNumber =0;
public static MsgUser ower=new MsgUser();
	@Override
	public boolean login(QQUser user) throws IOException {
		return false;
	}

	public static void main(String argus[]) throws Exception{
		
		BaseFrame.intSubstance();
	     try {
			java.awt.EventQueue.invokeAndWait(new Runnable() {
			     public void run() {
			       EIMLoginFrame loginFrame=EIMLoginFrame.getInstance();
			  	   BaseFrame.centerWindow(loginFrame);
			  	   loginFrame.setVisible(true);
			     }
			 });
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		} catch (InvocationTargetException e1) {
			e1.printStackTrace();
		}
		boolean loginState = false;
		while(true){
			loginState=WaitLoginFrame.getLoginState();
			Thread.sleep(2000);
				System.out.println("登陆状态检测loginState："+loginState);
			if(loginState)
				break;
		}
		System.out.println("登陆成功");
		WaitLoginFrame.getInstance().setVisible(false);
		setQqNumber(WaitLoginFrame.getInstance().qqNumber);
		EIMMainFrame.setFriends(TestEIMTree.getDatas(getQqNumber()));
		
		ower.setOnline(false);
		ower.setAttribute("headImage", "1");
		ower.setUserID("222");
		int qqnumber=WaitLoginFrame.qqNumber;
		QQUser user =SessionContex.getQQUser(qqnumber);
		String niname =new String(user.getAttr("niname"),"UTF-8");
		ower.setUserName(niname);
		niname+=" ";
		niname+=new String(user.getAttr("qianming"),"UTF-8");
		ower.setPersonWord(niname);
		EIMMainFrame.setOwer(ower);
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				EIMMainFrame mainframe = EIMMainFrame.getInstance();
				mainframe.changTryIcon();
				BaseFrame.leftWindow(mainframe);
				mainframe.setVisible(true);
			}
		});				
	}

	public static int getQqNumber() {
		return qqNumber;
	}

	public static void setQqNumber(int qqNumber) {
		IMQQLogin.qqNumber = qqNumber;
	}
	
}
